<?php


namespace App\Model;


use Illuminate\Support\Facades\DB;

class Qxlove extends BaseModel
{
    protected $activityConn = 'activity'; //数据库地址
    protected $connection = 'api'; //前台数据库地址
    protected $giftable = 'gift_library'; //礼物列表
    protected $sendgiftlog_table = 'qxlove_send_gift_log'; //七夕活动礼物送出记录

    /**
     * 获取送出礼物统计
     * @param int $page 页码
     * @param int $limit 总条数
     */
    public function getGiftSendList($page=1,$limit=10)
    {
        $res = DB::connection($this->activityConn)->table($this->sendgiftlog_table)
        ->selectRaw('SUM(send_num) as send_num,SUM(damion_value) as damion_value,COUNT(DISTINCT send_user) as send_user_num,gift_id')
        ->groupBy('gift_id')
        ->get();
        $res = $this->objToArray($res);
        return $res;
    }
    /**
     * 礼物送出总数
     */
    public function getGiftNums($giftid)
    {
        $data = DB::connection($this->activityConn)->table($this->sendgiftlog_table)
        ->where('gift_id',$giftid)
        ->sum('send_num');
        return $data;
    }
    /**
     *对应礼物钻石总数
     */
    public function getGiftDamionNums($giftid)
    {
        $data = DB::connection($this->activityConn)->table($this->sendgiftlog_table)
        ->where('gift_id',$giftid)
        ->sum('damion_value');
        return $data;
    }
    /**
     * 获取对应礼物送出userID
     */
    public function getUserGiftNums($giftid)
    {
        $data = DB::connection($this->activityConn)->table($this->sendgiftlog_table)
        ->where('gift_id',$giftid)
        ->select('send_user')
        ->distinct()
        ->get();
        $data = $this->objToArray($data);
        return $data;
    }
    /**
     * 获取礼物信息
     * @param $gid 礼物id
     */
    public function getGifInfo($gid)
    {
        $data = DB::connection($this->connection)->table($this->giftable)->where('gift_id',$gid)->first(['name']);
        $data = $this->objToArray($data);
        return $data;
    }

}